package com.itxiuyixiu.homework.entity.dao;

import com.itxiuyixiu.homework.entity.model.RewardsAndPunishment;
import com.itxiuyixiu.homework.entity.vo.RewardsAndPunishmentVo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author 黄磊
 * @date 2020/3/5
 */
public interface RewardsAndPunishmentDao extends JpaRepository<RewardsAndPunishment, Integer> {
    boolean existsByStudentStudentId(String studentId);

    @Transactional(readOnly = true)
    @Query(value = "select id, detail, gmtCreated, gmtModified, rewarded, time, title, fk_student_studentId as studentId from RewardsAndPunishment where id=?1" , nativeQuery = true)
    List<RewardsAndPunishmentVo> findAllById(int id);

    @Transactional(readOnly = true)
    @Query(value = "select id, detail, gmtCreated, gmtModified, rewarded, time, title, fk_student_studentId as studentId from RewardsAndPunishment where rewarded=?1" , nativeQuery = true)
    List<RewardsAndPunishmentVo> findAllByRewarded(boolean rewarded);

    @Transactional(readOnly = true)
    @Query(value = "select id, detail, gmtCreated, gmtModified, rewarded, time, title, fk_student_studentId as studentId from RewardsAndPunishment where fk_student_studentId=?1" , nativeQuery = true)
    List<RewardsAndPunishmentVo> findAllByStudentId(String studentId);

    @Transactional(readOnly = true)
    @Query(value = "select id, detail, gmtCreated, gmtModified, rewarded, time, title, fk_student_studentId as studentId from RewardsAndPunishment" , nativeQuery = true)
    List<RewardsAndPunishmentVo> findAllRewardsAndPunishment();
}
